package zheezes.protocol.impl.gbw.afn0d;

import java.util.ArrayList;
import java.util.List;

import zheezes.protocol.impl.gbw.format.DataForm06;
import zheezes.protocol.impl.gbw.format.DataForm09;


public abstract class AbstractAfn0DUpCurrentCurveDataUnit extends AbstractAfn0DCurveDataDataUnit {
	private List<DataForm06> list = new ArrayList<DataForm06>();
	
	@Override
	public int sizeOfData() {
		return super.sizeOfData() + getAmount() * DataForm06.SIZE;
	}

	@Override
	public int getData(byte[] buf, int offset) {
		int idx = offset;
		idx += super.getData(buf, idx);
		for (DataForm06 df : list) {
			idx += df.getBytes(buf, idx);
		}
		return idx - offset;
	}

	@Override
	public int setData(byte[] buf, int offset, int max) {
		int idx = offset;
		idx += super.setData(buf, idx, max);
		for (int i = 0; i < getAmount(); i++) {
			DataForm06 df = new DataForm06();
			idx += df.setBytes(buf, idx);
			list.add(df);
		}
		
		return idx - offset;
	}
	
	public DataForm06[] getData() {
		return list.toArray(new DataForm06[0]);
	}
}

